<template>
	<view class="pad-16r">
		<!-- 地址管理 -->
		<view v-for="(item,index) in dataSource" :key="index">
			<view class="item">
				<view class="start-center line-height-35 font-size-20">
					<view class="color-blue"><u-icon name="map"></u-icon></view>
					<view class="mar-0-5 font-weight">{{item.name}}</view>
					<view>{{item.phone}}</view>
				</view>
				<view class=" line-height-35">
					{{item.province}}{{item.city}}{{item.district}}{{item.address}}
				</view>
				<view class="border-row line-height-35"> </view>
				<view class="between-align line-height-35">
					<view class="start-center">
						<u-radio-group v-model="item.status">
							<u-radio @change="radioChange(item)" name="1">默认地址</u-radio>
						</u-radio-group>
						<!-- <view @click="radioChange(item)"></view> -->
					</view>
					<view class="start-center">
						<view class="color-blue mar-0-10" @click="toPage(item)">
							<u-icon name="edit-pen-fill"></u-icon>
							编辑
						</view>
						<view class="color-red mar-0-10" @click="openDialog(item)">
							<u-icon name="trash-fill"></u-icon>
							删除
						</view>
					</view>
				</view>
			</view>
		</view>
		<ButtonVue content="新增地址" @click="toPage({patId:userInfo.patId})"></ButtonVue>
		<u-toast ref="uToast" />
		<DialogVue :show="showModal" @confirm="confirm" @close="showModal=false" title="温馨提示" :mask-close-able="true">
			<view class="slot-content">

				<view class="text-center">
					确定要删除吗？
				</view>
			</view>
		</DialogVue>
	</view>
</template>

<script>
	import {
		mapGetters,
	} from 'vuex';
	import {
		patAddressSelect,
		patAddressStatus,
		patAddressDelete
	} from '../../api/patAddress';
	import DialogVue from '../../components/Dialog/Dialog.vue';
	import ButtonVue from '../../components/Button/Button.vue';
	export default {
		components: {
			DialogVue,
			ButtonVue
		},
		computed: {
			...mapGetters([
				'userInfo', 'hostApi'
			]),
		},
		data() {
			return {
				dataSource: [],
				showModal: false,
				dataItem: {},
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			init() {
				patAddressSelect({
					patId: this.userInfo.patId,
				}).then(res => {
					this.dataSource = res;
				})
			},
			radioChange(e) {
				console.log(e.status)
				patAddressStatus(e).then(res => {
					this.init()
					this.$refs.uToast.show({
						title: '默认成功',
						type: 'success',
					})
				})
			},
			openDialog(item) {
				this.dataItem = item;
				this.showModal = true;
			},
			confirm() {
				patAddressDelete(this.dataItem).then(res => {
					this.init()
					this.showModal = false
				})
			},
			toPage(item) {
				uni.navigateTo({
					url: `/pages/User/AddressUpdate?item=` + JSON.stringify(item)
				})
			}
		}
	}
</script>

<style>
</style>